//
//  TreeTableViewCell.m
//  X-Touch2
//
//  Created by shengchao yang on 12-3-28.
//  Copyright (c) 2012年 foxhis. All rights reserved.
//

#import "TreeTableViewCell.h"
#import "TreeTableViewCellController.h"
#import "UIBadgeView.h"
#import "DataBaseAccess.h"
#import "FileManager.h"

@implementation TreeTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        TreeTableViewCellController *cellController = [[[TreeTableViewCellController alloc] initWithNibName:@"TreeTableViewCellController" bundle:nil] autorelease];
        [self.contentView addSubview:cellController.view];
        
        UIBadgeView *badgeView=[[[UIBadgeView alloc] initWithFrame:CGRectMake(45, 1, 30, 20)] autorelease];
        badgeView.tag = TagOfUIView+1;
        badgeView.hidden = YES;
        badgeView.badgeColor = [UIColor redColor];
        [self.contentView addSubview:badgeView];
        [badgeView release];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];
}

-(void) setData:(NSString *)data sortCode:(NSString *)psCode{
    NSString * str1 = [NSString stringWithFormat:data];
    NSString * str2 = [NSString stringWithFormat:psCode];
    UILabel *lbl = (UILabel *)[self.contentView viewWithTag:TagOfUILabel];
    lbl.text = str1;
    
    float pluSortCount = [DataBaseAccess getPluSortCount:str2];
    UIBadgeView *badgeView = (UIBadgeView *)[self.contentView viewWithTag:TagOfUIView+1];
    if (pluSortCount > 0) {
        NSString * str3 =  [NSString stringWithFormat:@"%d",(int)pluSortCount];
        badgeView.badgeString = str3;
        badgeView.hidden = NO;
    }else {
        badgeView.hidden = YES;
    }
}
//设置选中状态
-(void) setSelectedCell:(BOOL)selected{
    UILabel *lblPluSortName = (UILabel *)[self viewWithTag:TagOfUILabel];
    UIImageView *imgPluSortBkg = (UIImageView *)[self viewWithTag:TagOfUIImageView + 10];
    if (selected) {
        imgPluSortBkg.image = [FileManager getImage:@"plusort1_bkg.png" type:3 withRect:imgPluSortBkg.frame];
        [lblPluSortName setTextColor:RGBA(255, 114, 0, 255)];
    }else {
        imgPluSortBkg.image = [FileManager getImage:@"plusort_bkg.png" type:3 withRect:imgPluSortBkg.frame];
        [lblPluSortName setTextColor:RGBA(0, 140, 214, 255)];
    }
}
-(void) dealloc{
    MyNSLog(@"TreeTableViewCell dealloc index=%d", self.tag - TagOfUITableViewCell);
    [super dealloc];
}

@end
